var vo={};

$(function(){
	var openWindow=window.document;
	var searchHeight=$("#divform").height();
	$("#listSjbb").height($(openWindow).height()-$(openWindow).height()*0.05-searchHeight)-10;
	var pwidth=$(openWindow).width()-20;
	$("#listSjbb").width($(openWindow).width()-20);
	$("#tjfs").val("dealerid");
	vo.tjfs=$("#tjfs").val();
	$("#dealer").addClass("a_hover");
	$("#listSjbb").datagrid({
					url:'/sjbb/gettjsjbb',
					title:'统计列表',
					method:'get',
					pagination:true,
					pageList: [1,10],
					loadMsg:'加载中......',
					singleSelect:true,
					nowrap:true,
					view: detailview,
					showFooter:true,
					columns:[[ 
					          {field:'dealerid',title:'经销商编号', align:'left',width:100,sortable:true},
					          {field:'dealername',title:'经销商名称', align:'left',width:100},
					          {field:'shopid',title:'门店编号', align:'left',width:100,sortable:true},
					          {field:'shopname',title:'门店名称', align:'left',width:100},
					          {field:'deviceid',title:'设备编号', align:'left',width:100,sortable:true},
					          {field:'devicename',title:'设备名称', align:'left',width:100},
					          {field:'standard',title:'合格数量（条）', align:'left',width:100},
					          {field:'count',title:'数量（条）', align:'left',width:100}
					]],
					detailFormatter:function(index,row){
			            return '<div style="padding:2px"><table id="standardview' + index + '">'+
			            '</table></div><div style="margin-top:5px">'+
			            '<table id="countview' + index + '"></table></div>';
			     },
			     onExpandRow:function(index,row){
			    	var begintime=$('#beginTime').datebox('getValue');
			 		var endtime=$('#endTime').datebox('getValue');
			    	 var id='';
			    	 if(vo.tjfs=='deviceid'){
			    		 id=row.deviceid;
			    	 }
			    	 else if(vo.tjfs=='shopid'){
			    		 id=row.shopid;
			    	 }
			    	 else{
			    		 id=row.dealerid;
			    	 }
			    	 $("#standardview"+index).datagrid({
			    		 	url:'/sjbb/getstandard',
			    		 	queryParams:{'id':id,'tjfs':vo.tjfs,'begintime':begintime,'endtime':endtime},
							title:'合格数据列表',
							method:'get',
							pagination:true,
							width:pwidth-100,
							pageList: window.subPageSize,
							loadMsg:'加载中......',
						    columns:[[
						              	 {field:'username',title:'用户名称', align:'left',width:100},
										 {field:'huiyuanziliao_jianchariqi',title:'检查日期',width:80,align:'center',sortable:true},
										 {field:'shopid',title:'门店编号', align:'left',width:100,sortable:true},
								         {field:'shopname',title:'门店名称', align:'left',width:100,sortable:true},
								         {field:'deviceid',title:'设备编号',align:'left',width:120},
								         {field:'devicename',title:'设备名称',align:'left',width:80,},
								         {field:'modelname',title:'设备型号',align:'left',width:80},
								         {field:'rtc_shengao',title:'身高',align:'left',width:50,},
								         {field:'rtc_tizhong',title:'体重',align:'left',width:50,},
								         {field:'rtc_bmi',title:'bmi指数',align:'left',width:50,},
								         {field:'rtc_gaoya',title:'高压',align:'left',width:50,},
								         {field:'rtc_diya',title:'低压',align:'left',width:50,},
								         {field:'rtc_xinlv',title:'心率',align:'left',width:50,},
								         {field:'rtc_xueyang',title:'血氧',align:'left',width:50,}
								     ]],
						    onResize:function(){  
				                    $('#listSjbb').datagrid('fixDetailRowHeight',index);  
				                },
			                onLoadSuccess:function(){  
			                    setTimeout(function(){  
			                        $('#listSjbb').datagrid('fixDetailRowHeight',index);  
			                    },0);  
			                },
			    	 });
			    	 $("#countview"+index).datagrid({
			    		 	url:'/sjbb/getcount',
			    		 	queryParams:{'id':id,'tjfs':vo.tjfs,'begintime':begintime,'endtime':endtime},
							title:'不合格数据列表',
							method:'get',
							width:pwidth-100,
							pagination:true,
							pageList: window.subPageSize,
							loadMsg:'加载中......',
						    columns:[[
						              	 {field:'username',title:'用户名称', align:'left',width:100},
										 {field:'huiyuanziliao_jianchariqi',title:'检查日期',width:80,align:'center',sortable:true},
										 {field:'shopid',title:'门店编号', align:'left',width:100,sortable:true},
								         {field:'shopname',title:'门店名称', align:'left',width:100,sortable:true},
								         {field:'deviceid',title:'设备编号',align:'left',width:120},
								         {field:'devicename',title:'设备名称',align:'left',width:80,},
								         {field:'modelname',title:'设备型号',align:'left',width:80},
								         {field:'rtc_shengao',title:'身高',align:'left',width:50,},
								         {field:'rtc_tizhong',title:'体重',align:'left',width:50,},
								         {field:'rtc_bmi',title:'bmi指数',align:'left',width:50,},
								         {field:'rtc_gaoya',title:'高压',align:'left',width:50,},
								         {field:'rtc_diya',title:'低压',align:'left',width:50,},
								         {field:'rtc_xinlv',title:'心率',align:'left',width:50,},
								         {field:'rtc_xueyang',title:'血氧',align:'left',width:50,}
								     ]],
						    onResize:function(){  
				                    $('#listSjbb').datagrid('fixDetailRowHeight',index);  
				                },
			                onLoadSuccess:function(){  
			                    setTimeout(function(){  
			                        $('#listSjbb').datagrid('fixDetailRowHeight',index);  
			                    },0);  
			                },
			    	 });
			    	 $('#listSjbb').datagrid('fixDetailRowHeight',index);
			     }
				});
	$("#listSjbb").datagrid('hideColumn','shopid');
	$("#listSjbb").datagrid('hideColumn','shopname');
	$("#listSjbb").datagrid('hideColumn','deviceid');
	$("#listSjbb").datagrid('hideColumn','devicename');
	$(".shide").hide();
	$(".dhide").hide();
	$('.datagrid-row-detail>#asdf>li').click(function(){
		var _this= $(this).index();
	   $('.datagrid-row-detail>.main_con>.content').eq(_this).addClass('disBlock').siblings('.disBlock').removeClass('disBlock');
	 })
	$("#serbutton").click(function(){
		vo.tjfs=$("#tjfs").val();
		if(vo.tjfs=="dealerid"){
			$("#listSjbb").datagrid('showColumn','dealerid');
			$("#listSjbb").datagrid('showColumn','dealername');
			$("#listSjbb").datagrid('hideColumn','shopid');
			$("#listSjbb").datagrid('hideColumn','shopname');
			$("#listSjbb").datagrid('hideColumn','deviceid');
			$("#listSjbb").datagrid('hideColumn','devicename');
			$(".shide").hide();
			$(".dhide").hide();
		}
		if(vo.tjfs=='shopid'){
			$("#listSjbb").datagrid('showColumn','shopid');
			$("#listSjbb").datagrid('showColumn','shopname');
			$("#listSjbb").datagrid('hideColumn','deviceid');
			$("#listSjbb").datagrid('hideColumn','devicename');
			$(".shide").show();
			$(".dhide").hide();
		}
		if(vo.tjfs=='deviceid'){
			$("#device").addClass("a_hover");
			$("#listSjbb").datagrid('showColumn','deviceid');
			$("#listSjbb").datagrid('showColumn','devicename');
			$(".shide").show();
			$(".dhide").show();
		}
		vo.begintime=$('#beginTime').datebox('getValue');
		vo.endtime=$('#endTime').datebox('getValue');
		vo.dealerid=$("#dealerid").val();
		vo.shopid=$("#shopid").val();
		vo.deviceid=$("#deviceid").val();
		$("#listSjbb").datagrid('load',vo);
	});
	$("#listSjbb").datagrid({
		toolbar: '#tb'
	});
	$('#beginTime').datebox({});  
	$('#endTime').datebox({}); 
});
/**
 * 按统计方式统计查询
 * @param status
 */
function searchStatus(status){
	var sta='';
	if(status=="dealerid"){
		$("a").removeClass("a_hover");
		$("#dealer").addClass("a_hover");
		$(".shide").hide();
		$(".dhide").hide();
	}
	if(status=="shopid"){
		$("a").removeClass("a_hover");
		$("#shop").addClass("a_hover");
		$(".shide").show();
		$(".dhide").hide();
	}
	if(status=="deviceid"){
		$("a").removeClass("a_hover");
		$("#device").addClass("a_hover");
		$(".shide").show();
		$(".dhide").show();
	}
	$("#tjfs").val(status);
	vo.tjfs=status;
}
/**
 * 导出为excel
 */
function exportXls(){
	vo.dealerid=getVal(vo.dealerid);
	vo.shopid=getVal(vo.shopid);
	vo.deviceid=getVal(vo.deviceid);
	vo.begintime=getVal(vo.begintime);
	vo.endtime=getVal(vo.endtime);
	if(vo.tjfs==''||vo.tjfs=='undefined'||vo.tjfs==undefined){
		$.messager.alert("失败","统计方式不能为空：",'error');
		return;
	}
	var url='/sjbb/exportXls?dealerid='+vo.dealerid+'&shopid='+vo.shopid+'&deviceid='+
	vo.deviceid+'&begintime='+vo.begintime+'&endtime='+vo.endtime+'&tjfs='+vo.tjfs;
	window.open(url,'','',false);
}

